package com.ibiaoke.goods.service;

import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.utils.AssertUtils;
import com.ibiaoke.goods.dao.ReportLossDao;
import com.ibiaoke.goods.entity.ReportLoss;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class ReportLossServiceImpl implements  ReportLossService{

    @Autowired
    private ReportLossDao reportLossDao;

    @Autowired
    private XcxShopPriceService xcxShopPriceService;

    @Transactional
    @Override
    public Integer addReportLoss(String userName,ReportLoss reportLoss) {
        AssertUtils.notNull(reportLoss.getLossNum(), "报损量不能为空");
        AssertUtils.notNull(reportLoss.getLossPrice(), "报损金额不能为空");
        AssertUtils.notNull(reportLoss.getShopId(), "shopId不能为空");
        AssertUtils.notNull(reportLoss.getGoodId(), "goodId不能为空");
        reportLoss.setOperator(userName);
        reportLoss.setShopId(reportLoss.getShopId());
        reportLoss.setCreateTime(new Date());
        reportLossDao.insert(reportLoss);
        xcxShopPriceService.modifyReportLossShopNum(reportLoss);
        return null;
    }

    @Override
    public List<ReportLoss> findReportLossList(String goodName, Integer goodId, Date loss_time,
                                               Date lossEndtime,Integer shopId,Page page) {

        return reportLossDao.selectReportLoss(goodName,goodId,loss_time,lossEndtime,shopId,page);
    }
}
